#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    while(cin >> n){
        if(n == 0) break;
        double sum = 0;
        vector<int> nums(n);
        for(int i = 0; i < n; ++i){
            cin >> nums[i];
            sum += nums[i];
        }
        double ave = sum / n, sqrsum = 0;
        for(int i = 0; i < n; ++i){
            sqrsum += (ave - nums[i]) * (ave - nums[i]);
        }
        cout << (int)(sqrsum / n) << endl;
    }
}